
#include <cassert>
#include <winsock2.h>
#include "sockexcept.h"


static inline LPSTR GetErrorMessage(LPSTR pBuf, int bufSize, int err )
{
	assert( pBuf );
	DWORD dwResult = FormatMessageA(
		FORMAT_MESSAGE_FROM_SYSTEM,
		0,
		err,
		MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US ),
		pBuf, 
		bufSize, 
		0);

	return pBuf;
}

static inline std::string GetWSAErrorMessage( int err )
{
	char buf[300];
	GetErrorMessage( buf, 300, err );
	return buf;
	return "";
}

SocketError::SocketError( const std::string & s ): std::exception( ("Error on socket: " + s).c_str() )
{

}

SocketError::SocketError( int err ): std::exception( GetWSAErrorMessage(err).c_str() ) 
{

}